1B11 Programming Exercises 6

Marking finishes Friday 16th February 2001

It is recommended that you finish by Friday 9th February

Purpose: Object-oriented programming.

Goal: Complete as many of these questions as you can. If you are keeping up, you need to do at least the Core questions. The Additional questions are more challenging and are designed to stretch the more confident programmers. Don't worry if you can't do them now, but be prepared to come back and try them later on in the term.

Marking: All questions are binary marked.
To get a question marked, print out the program you have written and a cover sheet from the 1b11 web page. Fill in the cover sheet and attach it to the program listing, then take the work to your lab group demonstrator for marking. The demonstrator may want to see a demonstration of your program running. An answer can be submitted as many times as you like, until it is satisfactory.
All printing should be done on the line printer (a4lp) - don't use up your laser printer quota!

NOTE: You must keep all marked work as it forms a record of your progress. At the end of the course you are required to resubmit all work.


Programming Notes

The background information for these exercises was covered in the lectures on the design and implementation of small object-oriented programs (including those on the Snack Bar example).


Q6.1 Take your own copy of the Snack Bar program files available from the 1b11 web page. Modify and extend the program to deal with the following stories:

a) A meal is a fixed combination of menu items, for example: chips + burger + drink. The price of a meal is less than the combined price of the individual items. A menu can include one or more meals. A meal can only include menu items from the current menu.

b) A daily record of all orders should be kept, along with the numbers of each menu item and meal sold, and the total money taken for the day.

c) A Snack Bar is open from 7am to 10pm Monday to Saturday, and 8am to 6pm Sunday.

d) A weekly report of sales is required. It should tabulate the numbers of all menu items and meals sold, the total money taken for each item and the total money taken for the week.

e) The weekly report should also summarise the total money taken each day.

f) A record of the available stock of each menu item should be kept and updated at the end of each day.

g) New stock received should be recorded when it arrives and before it is sold.

h) Stock levels should be included in the daily and weekly records.

i) If the number of an item of stock falls below a given number at the end of the day, new stock must be ordered.

j) The sell-by date of stock must be checked regularly to ensure that no out-of-date item is sold.

Getting started

Remember, the stories describe what the client wants in order to run a Snack Bar, they don't dictate what the program must do or how it must be implemented. You must decide how to interpret each story and determine the tasks they represent. These tasks then need to be mapped to the classes/objects and methods of the program, using a technique like the CRC method. Some stories may lead to new classes in the program, others to modified behaviour of existing code, while some may deal with behaviour outside of the program altogether.

Spend time thinking about each story and determine how it might relate to the design of the Snack Bar program. For example: Does the opening time of the snack bar matter? Does checking the sell-by date imply that the dates are stored by program or just that it should be possible to delete some amount of some stock item? Is stock ordering done over the phone or does the program do it?

Don't try and deal with all the stories at one go. Group related stories together and work through them step by step. Keep things simple (but not trivial!) and complete as many of the extensions as you have time to do. It is better to perform a progressive series of modifications and extensions to your program, with each update resulting in a complete working program. A later version of the program may result in changing or removing code from a previous version — don't worry about this happening, it is much better than trying to do a number of changes at once and getting stuck because they turn out to be too complicated. It is a very good idea to save a copy of each working version before starting on the next. If things go wrong you can quickly return to the last working version.

Testing

Your modified Snack Bar program must be thoroughly tested. Each class should have a corresponding test harness class. Test everything, no excuses.

Working with daily and weekly reports will require a fair amount of test data, which should be stored in files. Use the test harness classes to do the tedious work of reading the test data and checking the results of using it.


Additional Questions for those who want a challenge

Q6.2 Add a Graphical User Interface to your Snack Bar program.


Q6.3 The Snack Bar has been very successful and the owner has started to open a chain of snack bars across the country. Write a separate program that can take all the reports generated by the Snack Bar program and produce a combined report for the entire chain. Include graphs and charts as part of the report.